package com.xiaoniu.forum.web.controller;

import java.util.Arrays;
import java.util.Map;

import cn.hutool.core.bean.BeanUtil;
import com.xiaoniu.forum.common.utils.CommonQueryVo;
import com.xiaoniu.forum.entity.MemberEntity;
import com.xiaoniu.forum.entity.MemberNospeakEntity;
import com.xiaoniu.forum.entity.dto.NoSpeakDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
//import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xiaoniu.forum.service.MemberService;
import com.xiaoniu.forum.common.utils.PageUtils;
import com.xiaoniu.forum.common.utils.R;



/**
 * 用户表(前台用户，后台用户数据在sys_user表)
 *
 * @author xiaoniu
 * @email 55333@qq.com
 * @date 2021-03-20 13:55:56
 */
@RestController
@RequestMapping("forum/member")
@Api("member管理")
public class MemberController {
    @Autowired
    private MemberService memberService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @ApiOperation("查看列表")
    //@RequiresPermissions("forum:member:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 多条件查询列表
     */
    @PostMapping("/multiConditList")
    @ApiOperation("多条件查询列表")
    //@RequiresPermissions("forum:tabbaritem:list")
    public R multiConditList(@RequestBody CommonQueryVo queryVo){
        System.out.println(queryVo);
        PageUtils page = memberService.multiConditPage(queryVo);
        return R.ok().put("page",page);
    }

    /**
     * 多条件查询列表（带用户禁言信息）
     */
    @PostMapping("/multiConditMemberVoList")
    @ApiOperation("多条件查询列表")
    //@RequiresPermissions("forum:tabbaritem:list")
    public R multiConditMemberVoList(@RequestBody CommonQueryVo queryVo){
        System.out.println("2222222222233333333333444444444444444");
        PageUtils page = memberService.multiConditMemberVoList(queryVo);
        return R.ok().put("page",page);
    }



    /**
     * 信息（带用户禁言信息）
     */
    @RequestMapping("/info/{id}")
    @ApiOperation("根据ID查看")
    //@RequiresPermissions("forum:member:info")
    public R info(@PathVariable("id") String id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ApiOperation("保存数据")
    //@RequiresPermissions("forum:member:save")
    public R save(@RequestBody MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation("修改数据")
    //@RequiresPermissions("forum:member:update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ApiOperation("批量删除")
    //@RequiresPermissions("forum:member:delete")
    public R delete(@RequestBody String[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 禁言用户
     */
    @PostMapping("/nospeak")
    @ApiOperation("禁言")
    public R noSpeak(@RequestBody NoSpeakDTO noSpeakDTO){
        MemberNospeakEntity nospeakEntity = new MemberNospeakEntity();
        BeanUtil.copyProperties(noSpeakDTO,nospeakEntity);
        memberService.nospeak(nospeakEntity,noSpeakDTO.getReason());
        return R.ok();
    }

    /**
     * 解除禁言
     */
    @PostMapping("/normalSpeak/{memberId}")
    @ApiOperation("解除禁言")
    public R normalSpeak(@PathVariable String memberId){
        memberService.normalSpeak(memberId);
        return R.ok();
    }

    /**
     * 禁用用户
     */
    @ApiOperation("根据id禁用账户")
    @PostMapping("/disable/{id}")
    public R disableMemberById(@PathVariable String id){
        memberService.disableMemberById(id);
        return R.ok();
    }

}
